import{Bt as e,a as t,c as n,d as r,n as i,r as a,u as o,ut as s,x as c}from"./B603vO-13smUKN.js";var l=`hxAppInterface`,u=!1;function d(){return globalThis?.webkit?.messageHandlers?.[l]}function f(e){e.force!=null&&(u=e.force)}function p(){return u||d()!=null}var m=s(`bridge-web`),h=class extends c{remoteInfo;deviceId;ready=!1;appInfo;constructor(e){super(),this.appInfo=e,this.on(`ready`,(e=>{m.info(`ready from native`,e),this.remoteInfo=e,this.deviceId=e?.deviceId,this.ready=!0})),globalThis.hxAppInterface=(e,t)=>{m(`handle`,e,t),super.emit(e,t)}}async emit(t,...n){let r={name:t,value:e(n[0])};return m(`emit`,r),d()?.postMessage(r),!0}emitReady(){this.emit(`ready`,{version:this.appInfo.version,app:this.appInfo.app})}onFunctions(e){let t=Object.entries(e).map(([e,t])=>this.on(e,t));return()=>t.forEach(e=>e())}};function g(e){if(e.force!=null&&f({force:e.force}),!p())return;globalThis.native&&m.warn(`A native bridge is already registered on globalThis`);let t=new h(e);return globalThis.native=t,t.emitReady(),t}var _=s(`bridge-web:env`),v;async function y(){if(p()){if(v)return v;try{let e=await fetch(`app-rest:///env`);if(!e.ok){_.warn(`/env request failed: ${e.status}`);return}return v=await e.json(),_.info(`native env: wid=${v?.wid} cid=${v?.cid}`),v}catch(e){_.warn(`/env fetch error`,e);return}}}function b(){return v}var x=n({osVersion:r(),clientId:r(),deviceId:r()}).meta({swiftName:`NativeInfo`}),S=n({controlAccent:r().optional(),controlBackground:r().optional(),label:r().optional(),link:r().optional(),separator:r().optional(),text:r().optional(),textBackground:r().optional(),underPageBackground:r().optional(),windowBackground:r().optional()}).meta({swiftName:`BridgeEnvSystemColors`}),C=n({did:r(),cid:r(),wid:r(),currencyCode:r(),locale:r(),language:r(),region:r(),decimalSeparator:r(),groupingSeparator:r(),firstDayOfWeek:t(),uses24HourClock:a(),appearanceIsLiquidGlass:a().default(!1),appearanceMode:r(),systemColors:S.meta({swiftType:`[String: String]`})}).meta({swiftName:`BridgeEnvResponse`}),w=n({itemId:r(),title:r().optional(),checked:a().optional(),disabled:a().optional(),separator:a().optional()}).meta({swiftName:`BridgeMenuItem`}),T=n({menuId:r(),x:t(),y:t(),items:i(w).meta({swiftType:`[BridgeMenuItem]`})}).meta({swiftName:`BridgeContextMenuRequest`}),E=n({id:r(),assets:i(n({cid:r(),idx:t(),name:r().optional(),size:t(),type:r(),checksum:r()})).meta({swiftType:`[BridgeAssetInfo]`})}).meta({swiftName:`BridgeAssetList`});o(n({version:t(),app:r()})),o(n({url:r()})),o(x),o(E).meta({swiftSkip:!0}),o(E).meta({swiftSkip:!0}),o(C),o(n({fullscreen:a()})),o(T).meta({swiftSkip:!0}),o(n({title:r(),message:r().optional(),mode:r().optional()})).meta({swiftSkip:!0}),o(n({menuId:r(),itemId:r()})).meta({swiftSkip:!0}),o(n({menuId:r()})).meta({swiftSkip:!0}),f({force:!0});var D=p();export{g as i,b as n,y as r,D as t};